
{% extends 'layout.html' %}
{% block css %}
    {% load staticfiles %}
    <style>
    .dropuser {
        margin-top: 25px;
        margin-left: 20px;
    }
    </style>
{% endblock %}

{% block menus %}
    {{ menu_string | safe }}
{% endblock %}

{% block content %}
<div class="dropuser">
    <form method="post" onsubmit="return false">
        {% csrf_token %}
        中文姓名：<input id="realname" class="input-all" type="text" name="realname" style="width:100px">
        <div id="drop" style="margin-left: 70px" class="btn-all">删除</div>
    </form>

    <div id="loading"></div>
    <div id="response"></div>
</div>

{% endblock %}
    {% block js %}
    <script>
    $(function () {
        $('#menu_teacher').addClass('active');
        $('#menu_teacher').next().removeClass('hide')
    })

        $(document).keydown(function (event) {
            if(event.keyCode == 13){
                $('#drop').click()
            }
        })
        $('#drop').click(function () {
            var realname = $('#realname').val().trim()
            if (realname.length == 0) {
                alert('姓名不能为空')
                return false
            }
            $.ajax({
                url: '/dropuser/',
                type: 'post',
                data: {realname: realname},
                beforeSend: function(XMLHttpReqeust){
                  $('#loading').html("<span style=\"color:red\">处理中..</span>")
                },
                success: function (rep) {
                    console.log(rep)
                    if(rep == 10000){
                        alert('请输入正确的中文姓名！')
                        return
                    }
                    var arr = Object.keys(rep)[0]

                    var val = Object.values(rep)

                    console.log('arr'+val)

                    if(arr.length == 1){
                        if(!val.status){
                            alert(val.name+ ': ' + val.error)
                        }else {
                            alert(val.data)
                        }
                    }else {
                        $.each(rep,function (i,item) {
                            if(!item.status){
                                alert(item.name+ ': ' + item.error)
                            }else {
                                alert(item.data)
                            }

                        })
                    }
                },
                complete: function (XMLHttpRequest,textStatus) {
                    $("#loading").empty();
                },
                error: function (msg) {
                    alert('发生错误' + msg.text)
                }
            })
        })
    </script>
    {% endblock %}
</body>
</html>
